//
//  WDTarBarController.swift
//  SINAWeiBo
//
//  Created by wangwei on 2016/11/12.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class WDTarBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //MARK:
        //MARK: 设置UI界面
        setupUI()
        //MARK:
        //MARK: 换掉系统的TabBar
        changeTabBar()
        
    }
    func changeTabBar() {
    
        let wdTabBar = WDTabBar()
        
        setValue(wdTabBar, forKey: "tabBar")
        
        //这里我们可以监听到TabBar 的作用
        wdTabBar.composeClick = { () -> () in
            print("我们监听到composeBtn 的点击,这个是在TabBar控制器中进行的")
        
        }
        
    }
    //MARK:
    //MARK: 设置UI界面
    func setupUI() {
        //MARK:
        //MARK: 添加子控制器
        addChildController()
        
    
    }
    func addChildController() {
        
        //这里面是添加四个子控制器
     addChildController(vc: WDHomeController(), title: "主页", imageName: "tabbar_home")
     addChildController(vc: WDMessageController(), title: "消息", imageName: "tabbar_message_center")
     addChildController(vc: WDDiscoverController(), title: "发现", imageName: "tabbar_discover")
     addChildController(vc: WDProfileController(), title: "个性", imageName: "tabbar_profile")

    }
    //MARK:
    //MARK: 添加子控制器的方法,这个运用到了方法的重载
    func addChildController(vc: UIViewController,title: String,imageName: String) {
        //首先设置标题(Nav)
        vc.navigationItem.title = title
        //第二个设置tabbar 标题
        vc.tabBarItem.title = title
        
        //第三步设置图片
        vc.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: (imageName + "_selected"))?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        //第四步设置文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.black], for: UIControlState.normal)
        //第五步字体的大小
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: UIControlState.normal)
        //第六步我们可以设置图片的偏移
      //  vc.tabBarItem.imageInsets = UIEdgeInsets.init(top: 10, left: 0, bottom: -10, right: 0)
        //第七部设置badge
        vc.tabBarItem.badgeValue = "10"
        vc.tabBarItem.badgeColor = #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)
        vc.tabBarItem.badgeTextAttributes(for: UIControlState.normal)
        
        //第八步包装导航控制器
        let nv = WDBaseNavController(rootViewController: vc)
        
        //第九步把创建好的控制器添加到TabBarController 上
        
        addChildViewController(nv)
        
        
    }
    
    


 

}
